#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django import template

register = template.Library()

def getattribute(value, arg):
    """Gets an attribute of an object dynamically from a string name"""

    if hasattr(value, str(arg)):
        return getattr(value, arg)
    elif hasattr(value, 'has_key') and value.has_key(arg):
        return value[arg]
    return "attribute request error"

register.filter('getattribute', getattribute)

# vim:set et sts=4 ts=4 tw=80:
